package com.farmer.reliablemessage;

import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

import java.io.InputStream;

/**
 * @author tech-famer
 * @ClassName: DatasourceConfiguration
 * @Description: (这里用一句话描述这个类的作用)
 * @date 2021/11/1 12:49
 */
@Configuration
@MapperScan(value = "com.farmer.reliablemessage.mapper",sqlSessionFactoryRef = "sqlSessionFactory")
public class DatasourceConfiguration {

    public DatasourceConfiguration(SqlSessionFactory sessionFactory){
        Logger logger = LoggerFactory.getLogger(DatasourceConfiguration.class);
        String[] mapperIds = {"MessageMapper","MessageManagerMapper"};
        org.apache.ibatis.session.Configuration mapperConfig = sessionFactory.getConfiguration();
        try {
            for (String mapperId : mapperIds) {
                InputStream is = ClassLoader.getSystemResourceAsStream("reliablemessagemapper/" + mapperId + ".xml");
                XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(is, mapperConfig, "com.farmer.reliablemessage.mapper." + mapperId, mapperConfig.getSqlFragments());
                xmlMapperBuilder.parse();
            }
            logger.info("reliablemessage mybatis xml init success!!!");
        }catch (Exception e){
            logger.error("reliablemessage mybatis xml init error!!! ");
        }
    }








}
